package com.qige.dome.homework;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @Author qige
 * @Date 2024-08-01 19:29
 * @Description
 */
public class homework4 {
    /*
    1.假如有以下email数据“aa@sohu.com,bb@163.com,cc@sina.com,..”
    现需要把email中的用户部分和邮件地址部分分离，分离后以键值对应的方式放入HashMap？
     */
    public static void main(String[] args) {
        String str= "aa@sohu.com,bb@163.com,cc@sina.com";
        Map<String,String> map = new HashMap<>();
        String[] strArr = str.split(",");
        for (int i = 0; i < strArr.length; i++) {
            String user = strArr[i].substring(0,strArr[i].indexOf("@"));
            String email = strArr[i].substring(strArr[i].indexOf("@")+1);
            map.put(user,email);
        }
        Set<String> keySet = map.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            String value = map.get(key);
            System.out.println(key + "--->" + value);
        }
    }
}
